<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习2</title>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
    <!-- 遍历checkbox控件，输出选中个数 -->
    <input type="checkbox" value="1" name="check" checked="checked" />
    <input type="checkbox" value="2" name="check"  />
    <input type="checkbox" value="3" name="check" checked="checked" />
    <input type="checkbox" value="4" name="check"   />
    <p></p>

    <script>
        $(':checkbox').change(() => {
            $('p').text('当前选中个数：' + $(':checked').length);
        })
    </script>
</body>
</html>